package com.example.myapplication1;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.text.Editable;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.style.ImageSpan;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.Checkable;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.weixinwo_main);

    }

    @Override
    public void onSaveInstanceState(@NonNull Bundle outState, @NonNull PersistableBundle outPersistentState) {
        super.onSaveInstanceState(outState, outPersistentState);
    }

    @Override
    protected void onRestoreInstanceState(@NonNull Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);
    }

    public void jumpToSetting(View view) {
        Intent intent = new Intent(MainActivity.this,MainActivity2.class);
        startActivity(intent);
    }

       /* public void initView(){
            EditText editUsername = findViewById(R.id.edit_name);
            EditText editPassword = findViewById(R.id.edit_pswd);
            Button btnLogin = findViewById(R.id.butt);
            CheckBox checkPassWord=findViewById(R.id.Check);
            CheckBox checkPassWord1=findViewById(R.id.xie);
            Switch switchSettings = findViewById(R.id.switch_settings);
            TextView textPwdStrong = findViewById(R.id.text_pwd_strong);
            Switch sos = findViewById(R.id.sss);

            //点击事件OnClickListener是 View.OnClickListener，父类点击事件，所有控件通用点击事件
            btnLogin.setOnClickListener(new View.OnClickListener() {
                //当用户点击控件时，便会触发点击事件，进而回调onClick()
                @Override
                public void onClick(View view) {
                    //获取用户是否勾选CheckBox
                    boolean isCheck = checkPassWord.isChecked();
                    boolean isCheck1 = checkPassWord1.isChecked();
                    boolean isOpen = switchSettings.isChecked();
                    //参数2：需要提示信息
                    //参数3：Tost显示时长 toast.LENGTH_SHORT Toast.LENGTH_LONG
                    String mobile=editUsername.getText().toString();
                    if (TextUtils.isEmpty(mobile))
                    {
                        Toast.makeText(MainActivity.this,
                                "用户名不可为空",
                                Toast.LENGTH_LONG).show();
                        return;
                    }

                    if (mobile.length() != 11)
                    {
                        Toast.makeText(MainActivity.this,
                                "手机号码不合法",
                                Toast.LENGTH_LONG).show();
                        return;
                    }
                    if(TextUtils.isEmpty(mobile)){
                        Toast.makeText(MainActivity.this,"登录成功",Toast.LENGTH_LONG).show();
                    }
                    Toast.makeText(MainActivity.this,"用户点击登录",

                            Toast.LENGTH_LONG).show();

                }
        });
            checkPassWord.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                 Toast.makeText(MainActivity.this,b?"用户同意协议":"用户拒绝协议",
                         Toast.LENGTH_LONG).show();
                }

            });
            checkPassWord1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton compoundButton, boolean isCheck1) {
                    Toast.makeText(MainActivity.this,isCheck1?"用户记住密码":"取消记住密码",
                            Toast.LENGTH_LONG).show();
                }
            });
            switchSettings.setOnCheckedChangeListener(
                    new CompoundButton.OnCheckedChangeListener()
                    {
                        @Override
                        public void onCheckedChanged(CompoundButton buttonView,
                                                     boolean isChecked)
                        {
                            Toast.makeText(MainActivity.this,
                                    isChecked ? "用户设置自动登录" : "用户关闭自动登录",
                                    Toast.LENGTH_LONG).show();
                        }
                    });
            sos.setOnCheckedChangeListener(
                    new CompoundButton.OnCheckedChangeListener()
                    {
                        @Override
                        public void onCheckedChanged(CompoundButton buttonView,
                                                     boolean bbq)
                        {
                            Toast.makeText(MainActivity.this,
                                    bbq ? "用户设置隐身登录" : "用户关闭隐身登录",
                                    Toast.LENGTH_LONG).show();
                        }
                    });

           // textPwdStrong.setText("密码强度低");
            editPassword.addTextChangedListener(new TextWatcher()
            {
                @Override
                public void beforeTextChanged(CharSequence s, int start, int count, int after)
                {
                }
                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count)
                {

                }
                @Override
                public void afterTextChanged(Editable s)
                {
                   *//* textPwdStrong.setText(
                            s.toString().length() < 6 ? "密码长度过小" : "密码正常");*//*
                    String content = s.toString();
                    if(!TextUtils.isEmpty(content) && content.length()>4 && content.contains("[")
                    ){
                        SpannableStringBuilder ssb = new SpannableStringBuilder();
                        ssb.append("/xk");
                        int dp = 10;
                        int px = (int) ((getResources().getDisplayMetrics().density * 10)+0.5f);
                        Drawable img = getResources().getDrawable(R.mipmap.ic_launcher);
                        img.setBounds(0,0,px,px);
                        ImageSpan imageSpan = new ImageSpan(img);
                        ssb.setSpan(imageSpan,0,3, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
                        editPassword.setText(ssb);
                    }
                }
            });
    }*/
}